﻿<UserControl x:Class="HeritageAcademy.Window.WindowFrame"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:local="clr-namespace:HeritageAcademy.Window"
	mc:Ignorable="d"
	UseLayoutRounding="True"
	d:DesignWidth="640" d:DesignHeight="480">
    
    <UserControl.Resources>
        <Style x:Key="OpacityButton" TargetType="{x:Type Button}">
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="Border" Background="Transparent">
                            <ContentPresenter
                              x:Name="cp"
                              Opacity="0.5"
                              Margin="{TemplateBinding Padding}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              RecognizesAccessKey="True"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True" >
                                <Setter TargetName="cp" Property="RenderTransform">
                                    <Setter.Value>
                                        <TranslateTransform Y="1" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="cp" Storyboard.TargetProperty="Opacity" To="1.0" Duration="00:00:00.1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="cp" Storyboard.TargetProperty="Opacity" Duration="00:00:00.2" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="cp" Storyboard.TargetProperty="Opacity" To="0.1" Duration="00:00:00.1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="cp" Storyboard.TargetProperty="Opacity" Duration="00:00:00.2" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

	<Grid x:Name="grid">
		<Grid.RowDefinitions>
			<RowDefinition Height="40"/>
			<RowDefinition Height="0.933*"/>
		</Grid.RowDefinitions>
        
        <!-- Drag target -->
        
		<Border x:Name="dragTarget" BorderBrush="#727A5C27" BorderThickness="0,0,0,1" SnapsToDevicePixels="True" Height="40">
			<Border.Background>
				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
					<GradientStop Color="White" Offset="0"/>
					<GradientStop Color="#FFD4D4D4" Offset="1"/>
				</LinearGradientBrush>
			</Border.Background>
		</Border>
        
        <!-- Window state buttons -->
        
		<Grid x:Name="ControlBtnGrid" HorizontalAlignment="Right" Margin="0">
			<StackPanel HorizontalAlignment="Right" Margin="0,0,13,0" VerticalAlignment="Center" Grid.Column="2" Orientation="Horizontal">
                
                <!-- Minimize -->
				<Button x:Name="MinimizeButton" Width="20" Height="30" Click="minimize_Click" >
					<Button.Style>
						<Style BasedOn="{StaticResource OpacityButton}" TargetType="{x:Type Button}">
							<Setter Property="Visibility" Value="Visible" />
							<Style.Triggers>
								<DataTrigger Binding="{Binding MainWindow.WindowState, Source={x:Static Application.Current}}" Value="Minimized">
									<Setter Property="Visibility" Value="Collapsed" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</Button.Style>
					<Canvas Width="12" Height="10">
						<Rectangle Canvas.Top="6" Width="10" Height="3" Stroke="Gray" StrokeThickness="2" />
					</Canvas>
				</Button>

                <!-- Maximize -->
                <Button x:Name="MaximizeButton" Width="20" Height="30" Click="maximize_Click" >
					<Button.Style>
						<Style BasedOn="{StaticResource OpacityButton}" TargetType="{x:Type Button}">
							<Setter Property="Visibility" Value="Visible" />
							<Style.Triggers>
								<DataTrigger Binding="{Binding MainWindow.WindowState, Source={x:Static Application.Current}}" Value="Maximized">
									<Setter Property="Visibility" Value="Collapsed" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</Button.Style>
					<Canvas Width="12" Height="10">
						<Rectangle Canvas.Top="1" Width="11" Height="9" Stroke="Gray" StrokeThickness="2"  />
					</Canvas>
				</Button>

                <!-- Restore -->
                <Button x:Name="RestoreButton" Width="20" Height="30" Click="restore_Click" >
					<Button.Style>
						<Style BasedOn="{StaticResource OpacityButton}" TargetType="{x:Type Button}">
							<Setter Property="Visibility" Value="Visible" />
							<Style.Triggers>
								<DataTrigger Binding="{Binding MainWindow.WindowState, Source={x:Static Application.Current}}" Value="Normal">
									<Setter Property="Visibility" Value="Collapsed" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</Button.Style>
					<Canvas Width="12" Height="10">
						<Rectangle Canvas.Left="3" Width="8" Height="7" Stroke="Gray" StrokeThickness="2" />
						<Rectangle Canvas.Top="3" Width="8" Height="7" Stroke="Gray" StrokeThickness="2" />
					</Canvas>
				</Button>

                <!-- Close -->
                <Button x:Name="CloseButton" Style="{StaticResource OpacityButton}" Width="20" Height="30" Margin="0,0,8,0" Click="close_Click" >
					<Path Width="10" Height="10" Stroke="Gray" StrokeThickness="2.2" Data="{DynamicResource CloseX}" Stretch="Fill" />
				</Button>
                    
			</StackPanel>
		
        </Grid>

        <!-- Main content -->
        <local:WindowContent Margin="0" Grid.Row="1"/>
	
    </Grid>
</UserControl>